package com.lovo.roomProject.student.service.impl;

import com.lovo.roomProject.pojo.CutPageBean;
import com.lovo.roomProject.pojo.StudentDO;
import com.lovo.roomProject.student.dao.StudentDAO;
import com.lovo.roomProject.student.dao.impl.StudentDAOImpl;
import com.lovo.roomProject.student.service.StudentService;

import java.util.List;

public class StudentServiceImpl implements StudentService {
    private StudentDAO studentDAO = new StudentDAOImpl();

    @Override
    public List listStudent() {
        return studentDAO.listStudent();
    }

    @Override
    public CutPageBean listStudentByPage(int current, String name, String className, String roomAddr) {
        return studentDAO.listStudentByPage(current,name,className,roomAddr);
    }


    @Override
    public StudentDO getById(int id) {
        return studentDAO.getByID(id);
    }

    @Override
    public void insert(StudentDO studentDO) {
        studentDAO.insert(studentDO);
    }

    @Override
    public void delete(int id) {
        studentDAO.delete(id);
    }

    @Override
    public void update(StudentDO studentDO) throws Exception {
        StudentDO oldStudentDO = studentDAO.getByID(studentDO.getId());
        if(oldStudentDO.getRoom()!=null&& oldStudentDO.getRoom().getId()==studentDO.getRoom().getId()){
            throw new Exception("你没有更换房间");
        }
        studentDAO.update(studentDO);
    }

}
